<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="库位编号" prop="locationId">
        <el-input
          v-model="queryParams.locationId"
          placeholder="请输入库位编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="物料编号" prop="goodsId">
        <el-input
          v-model="queryParams.goodsId"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="产品型号" prop="BARCODE">
        <el-input
          v-model="queryParams.BARCODE"
          placeholder="请输入产品型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="创建时间" prop="WAREDATES">
        <el-date-picker
          clearable
          v-model="queryParams.WAREDATES"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期时间"
          end-placeholder="结束日期时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择创建时间范围">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:BACK:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:BACK:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['system:BACK:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:BACK:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

<!--    <el-table v-loading="loading" :data="BACKList" @selection-change="handleSelectionChange">-->
    <el-table border
              ref="filterTable" v-loading="loading" :data="BACKList" @selection-change="handleSelectionChange">

            <el-table-column label="行号"  type="selection" width="55" align="center" />
            <el-table-column label="出库单号" align="center" prop="pickingid" />
            <el-table-column label="产线" align="center" prop="gropSc" />
            <el-table-column label="库位编号" align="center" prop="locationId" />
            <el-table-column label="托盘号" align="center" prop="ctl" />
            <el-table-column label="物料编号" align="center" prop="goodsId" />
            <el-table-column label="产品型号" align="center" prop="barcode" />
            <el-table-column label="备注" align="center" prop="goodsName" />
            <el-table-column label="数量" align="center" prop="goodsNum" />
            <el-table-column label="创建时间" align="center" prop="wareDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.wareDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>

      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:BACK:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:BACK:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="${comment}" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="putinId">
          <el-input v-model="form.putinId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="putinIdLine">
          <el-input v-model="form.putinIdLine" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="outId">
          <el-input v-model="form.outId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="storageId">
          <el-input v-model="form.storageId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="areaId">
          <el-input v-model="form.areaId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="locationId">
          <el-input v-model="form.locationId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="goodsTypeid">
          <el-input v-model="form.goodsTypeid" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="operatorMan">
          <el-input v-model="form.operatorMan" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="operatorDate">
          <el-date-picker clearable
                          v-model="form.operatorDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="REMARK">
          <el-input v-model="form.REMARK" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="VERSION">
          <el-input v-model="form.VERSION" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="productionDate">
          <el-date-picker clearable
                          v-model="form.productionDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="BARCODE">
          <el-input v-model="form.BARCODE" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ProDucLotId">
          <el-input v-model="form.ProDucLotId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="CTL">
          <el-input v-model="form.CTL" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="goodsName">
          <el-input v-model="form.goodsName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="Whseloc">
          <el-input v-model="form.Whseloc" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="HIGH">
          <el-input v-model="form.HIGH" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="wgh">
          <el-input v-model="form.wgh" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="wareDate">
          <el-date-picker clearable
                          v-model="form.wareDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="PICKINGID">
          <el-input v-model="form.PICKINGID" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="plcId">
          <el-input v-model="form.plcId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ENDCTL">
          <el-input v-model="form.ENDCTL" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="REMARK2">
          <el-input v-model="form.REMARK2" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="providerId">
          <el-input v-model="form.providerId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ONSHELFUSERID">
          <el-input v-model="form.ONSHELFUSERID" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="PARTDESC">
          <el-input v-model="form.PARTDESC" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="HASVOLUME">
          <el-input v-model="form.HASVOLUME" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="warehousingId">
          <el-input v-model="form.warehousingId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="upgoodsId">
          <el-input v-model="form.upgoodsId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="BarCodeTpe">
          <el-input v-model="form.BarCodeTpe" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="BarCodef">
          <el-input v-model="form.BarCodef" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="GropSc">
          <el-input v-model="form.GropSc" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="lx">
          <el-input v-model="form.lx" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="netWeigh">
          <el-input v-model="form.netWeigh" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="stsErp">
          <el-input v-model="form.stsErp" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="stsDj">
          <el-input v-model="form.stsDj" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="SPECIFICATION">
          <el-input v-model="form.SPECIFICATION" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="VKBUR">
          <el-input v-model="form.VKBUR" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="KUNAG">
          <el-input v-model="form.KUNAG" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ZVKBUR">
          <el-input v-model="form.ZVKBUR" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ZKUNAG">
          <el-input v-model="form.ZKUNAG" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ZSOURCE">
          <el-input v-model="form.ZSOURCE" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="QTBY1">
          <el-input v-model="form.QTBY1" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="QTBY2">
          <el-input v-model="form.QTBY2" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="QTBY3">
          <el-input v-model="form.QTBY3" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="QTBY4">
          <el-input v-model="form.QTBY4" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="QTBY5">
          <el-input v-model="form.QTBY5" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="QTBY6">
          <el-input v-model="form.QTBY6" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="goodsMeasureId">
          <el-input v-model="form.goodsMeasureId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="gltrp">
          <el-input v-model="form.gltrp" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBACK, getBACK, delBACK, addBACK, updateBACK } from "@/api/system/ckBack";

export default {
  name: "BACK",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      BACKList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stockId: null,
        putinId: null,
        putinIdLine: null,
        outId: null,
        storageId: null,
        areaId: null,
        locationId: null,
        goodsTypeid: null,
        goodsId: null,
        goodsNum: null,
        operatorMan: null,
        operatorDate: null,
        operatorType: null,
        REMARK: null,
        VERSION: null,
        oriNum: null,
        changeNum: null,
        productionDate: null,
        BARCODE: null,
        ProDucLotId: null,
        CTL: null,
        goodsName: null,
        Whseloc: null,
        HIGH: null,
        wgh: null,
        wareDate: null,
        PICKINGID: null,
        plcId: null,
        customerId: null,
        boxType: null,
        packingNum: null,
        ENDCTL: null,
        goodsNumSj: null,
        REMARK2: null,
        providerId: null,
        ONSHELFUSERID: null,
        PARTDESC: null,
        HASVOLUME: null,
        warehousingId: null,
        upgoodsId: null,
        BarCodeTpe: null,
        BarCodef: null,
        GropSc: null,
        lx: null,
        netWeigh: null,
        stsErp: null,
        stsDj: null,
        SPECIFICATION: null,
        VKBUR: null,
        KUNAG: null,
        ZVKBUR: null,
        ZKUNAG: null,
        ZSOURCE: null,
        QTBY1: null,
        QTBY2: null,
        QTBY3: null,
        QTBY4: null,
        QTBY5: null,
        QTBY6: null,
        goodsMeasureId: null,
        gltrp: null,
        WAREDATES: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listBACK(this.queryParams).then(response => {
        this.BACKList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        stockId: null,
        putinId: null,
        putinIdLine: null,
        outId: null,
        storageId: null,
        areaId: null,
        locationId: null,
        goodsTypeid: null,
        goodsId: null,
        goodsNum: null,
        operatorMan: null,
        operatorDate: null,
        operatorType: null,
        REMARK: null,
        VERSION: null,
        oriNum: null,
        changeNum: null,
        productionDate: null,
        BARCODE: null,
        ProDucLotId: null,
        CTL: null,
        goodsName: null,
        Whseloc: null,
        HIGH: null,
        wgh: null,
        wareDate: null,
        PICKINGID: null,
        plcId: null,
        customerId: null,
        boxType: null,
        packingNum: null,
        ENDCTL: null,
        goodsNumSj: null,
        REMARK2: null,
        providerId: null,
        ONSHELFUSERID: null,
        PARTDESC: null,
        HASVOLUME: null,
        warehousingId: null,
        upgoodsId: null,
        BarCodeTpe: null,
        BarCodef: null,
        GropSc: null,
        lx: null,
        netWeigh: null,
        stsErp: null,
        stsDj: null,
        SPECIFICATION: null,
        VKBUR: null,
        KUNAG: null,
        ZVKBUR: null,
        ZKUNAG: null,
        ZSOURCE: null,
        QTBY1: null,
        QTBY2: null,
        QTBY3: null,
        QTBY4: null,
        QTBY5: null,
        QTBY6: null,
        goodsMeasureId: null,
        gltrp: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.stockId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const stockId = row.stockId || this.ids
      getBACK(stockId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.stockId != null) {
            updateBACK(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBACK(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const stockIds = row.stockId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + stockIds + '"的数据项？').then(function() {
        return delBACK(stockIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/BACK/export', {
        ...this.queryParams
      }, `BACK_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
